package com.qf.springboot.thymeleaf.controller;

import com.qf.springboot.thymeleaf.pojo.User;
import com.qf.springboot.thymeleaf.service.IUserservice;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Controller
public class UserConotroller {

    @Autowired
    private IUserservice iUserservice;

    /**
     * 跳转到用户编辑页面
     */
    @RequestMapping(value = "/toUser")
    public String toArticleWrite() {
        return "add";
    }

    @RequestMapping("/listUser")
    public String listUser(Model model){
        List<User> users = iUserservice.listUser();
        System.out.println(users);
        model.addAttribute("listUser", users);


        return "list";
    }

    @RequestMapping("/save")
    public String saveUser(User user){
        iUserservice.saveUser(user);
        return "redirect:/listUser";
    }

    @RequestMapping(value ="/deleteUser")
    public String deleteUser(@RequestParam int id){
        iUserservice.deleteUser(id);
        return "redirect:/listUser";
    }

}
